package java_thinking.unit_18_IO._18_11;

import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

/**
 * @Desc:   用GZIP进行简单压缩
 * @author: cww
 * @DateTime: 2019-05-18 15:16
 */

public class GZIPcompress {
    private static String file1 = "src/maindemo/java/java_thinking/unit_18_IO/_18_11/GZIPcompress.gz";
    private static String file = "src/maindemo/java/java_thinking/unit_18_IO/_18_8/Redirecting.txt";
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new FileReader(file));
        String s1;
        while ((s1 = in.readLine()) != null) {
            System.out.println(s1);
        }
        BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file1)));
        System.out.println("Writing file");;
        int c;
        in = new BufferedReader(new FileReader(file));
        while ((c = in.read()) != -1) {
            out.write(c);
        }
        in.close();
        out.close();
        System.out.println("Reading file");
        BufferedReader in2 = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file1))));
        String s;
        while ((s = in2.readLine()) != null) {
            System.out.println(s);
        }
    }
}
